package com.hzncc.flowable_diboot.handler;

import com.diboot.core.handler.DefaultExceptionHandler;
import com.diboot.core.vo.JsonResult;
import com.hzncc.flowable_diboot.common.SapResult;
import com.hzncc.flowable_diboot.exception.BusinessException;
import com.hzncc.flowable_diboot.exception.SapException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
* 通用异常处理类
* @author MyName
* @version 1.0
* @date 2022-12-30
* Copyright © MyCompany
*/
@RestControllerAdvice
@Slf4j
public class GeneralExceptionHandler extends DefaultExceptionHandler{
 
    @ExceptionHandler(BusinessException.class)
    public JsonResult<?> handleBusinessException(BusinessException e){
        return JsonResult.FAIL_EXCEPTION(e.getMessage());
    }

    @ExceptionHandler(SapException.class)
    public SapResult<?> handleSapException(SapException e){
        return new SapResult("E",e.getMessage());
    }
 
}